//
//  ViewController.m
//  cardmenNew
//
//  Created by Dengzeyu on 15/12/29.
//  Copyright © 2015年 Dengzeyu. All rights reserved.
//

#import "ViewController.h"
#import "UMCommunity.h"
#import "Mainview/Mainviewcontroller.h"
#import "UMComHomeFeedViewController.h"

@interface ViewController ()
@property(nonatomic, strong)UIButton * homeButton;
@property(nonatomic,strong)UIButton * communityButton;
@property(strong,nonatomic) UIView *tabbarView;//自定义个底部的tabbar视图
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.delegate=self;
    UIImage * imagehome = [UIImage imageNamed:@"home"];
    imagehome= [imagehome  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * imagehomeselect = [UIImage imageNamed:@"homeselect"];
    imagehomeselect=[imagehomeselect  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * imagecom = [[UIImage imageNamed:@"community"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * imagecomselect = [[UIImage imageNamed:@"community_on"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [[self.tabarItem.items objectAtIndex:0] setImage:imagehome];
    [[self.tabarItem.items objectAtIndex:0]setSelectedImage:imagehomeselect];
    UIEdgeInsets insets = UIEdgeInsetsMake(2, 0, -2, 0);
    [self.tabarItem.items objectAtIndex:0].imageInsets =insets;
    [[self.tabarItem.items objectAtIndex:1] setImage:imagecom];
    [[self.tabarItem.items objectAtIndex:1] setSelectedImage:imagecomselect];
    [self.tabarItem.items objectAtIndex:1].imageInsets = insets;
    UIImage * backgroundImage = [[UIImage imageNamed: @"table_pic"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSLog(@"%f",self.tabarItem.frame.size.height);
    UIImageView *tabBarBackgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
                                                                                           self.tabarItem.frame.size.width, self.tabarItem.frame.size.height)];
       tabBarBackgroundImageView.image =backgroundImage;
    [self.tabarItem insertSubview:tabBarBackgroundImageView atIndex:0];
    self.tabBar.clipsToBounds =YES;
    self.tabarItem.shadowImage = [[UIImage alloc] init];
    
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
     int index = tabBarController.selectedIndex;
    
}
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    if (item.tag == self.selectedIndex) {
        NSLog(@"tongyi jiemian ");
    }
    UIImage * image= [[self.tabarItem.items objectAtIndex:0] selectedImage];
    NSLog(@"%f,%f",image.size.width,image.size.height) ;
}
-(void)viewDidAppear:(BOOL)animated
{
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)configTabbarView
{
    self.tabBar.hidden=YES;//隐藏掉系统的bar
    UIScreen *s=[UIScreen mainScreen];
    CGFloat wid=[s bounds].size.width;
    CGFloat height=[s bounds].size.height;
    
    self.tabbarView=[[UIView alloc]initWithFrame:CGRectMake(0, height-48, wid, 48)];
    self.tabbarView.backgroundColor=[UIColor clearColor];
    
    
    for (int i=0; i<2; i++)  //自定义的贴上按钮5个
    {
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(i*wid/5.0, 0, wid/5.0, 49);
//        UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"%d",i]];//设置自定义的按钮
//        [button setImage:image forState:UIControlStateNormal];
        if(i==0)
        {
        [button setTitle:@"主页" forState:UIControlStateNormal];
    }else
    {
            [button setTitle:@"社区" forState:UIControlStateNormal];
    }
        button.tag=i;
        [button addTarget:self action:@selector(tapButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.tabbarView addSubview:button];
    }
    [self.view addSubview:self.tabbarView];//自定的tabbar
    
}
-(void)tapButton:(UIButton *)button
{
    self.selectedIndex = button.tag;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
@end
